package com.chujian.framework.starter.echo;

import com.chujian.framework.echo.EchoConst;
import com.chujian.framework.echo.EchoCore;
import com.chujian.framework.echo.aop.EchoMethodAdvice;
import com.chujian.framework.echo.aop.EchoMethodMatcher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.Advisor;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.ComposablePointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * 回显自动装配
 */
@Configuration
@ConditionalOnProperty(name = "chujian.ctrl.echo.enabled", havingValue = "true", matchIfMissing = true)
@Slf4j
public class EchoAuthConfiguration {

    @Configuration
    @Import({
            EchoCore.class,
            EchoMethodAdvice.class
    })
    public class Config {

    }

    /**
     * 切面装配
     */
    @Bean(name = EchoConst.ECHO_AOP_ADVISER_BEAN)
    public Advisor echoAdvisor(EchoMethodAdvice advice) {
        Pointcut pointcut = new ComposablePointcut(
                new EchoMethodMatcher()
        );
        return new DefaultPointcutAdvisor(pointcut, advice);
    }

}
